<template>
  <div>
    <div class="screen-con-item" v-if="itemData">
      <div class="item-left" @click="openSingleScreen">
        <MapRoute :mapId="itemData.serial_no" :missionId="missionId" @getFlight="getFlightData"></MapRoute>
      </div>
      <div class="item-right">
        <div class="item-right-top">
          <div class="top-img">
            <img src="@/assets/img/home/avatar.png" alt="" />
          </div>
          <div class="top-info">
            <p>{{ itemData.contact_user }}</p>
            <p>{{ itemData.contact_mobile }}</p>
          </div>
        </div>
        <div class="item-right-con" v-if="flightData">
          <div class="item-right-con-left">
            <p>{{ flightData.speed }}</p>
            <p>飞行速度</p>
          </div>
          <div class="item-right-con-right">
            <p>{{ flightData.drone_height }}</p>
            <p>飞行高度</p>
          </div>
        </div>
        <div class="item-right-line"></div>
        <div class="item-right-bottom" v-if="flightMission">
          <p :title="`${flightMission.province}-${flightMission.city}-${flightMission.district}`">
            {{ flightMission.province }}-{{ flightMission.city }}-{{ flightMission.district }}
          </p>
          <div class="item-right-bottom-item">
            <p>设备品牌</p>
            <p>{{ itemData.brand_name }}</p>
          </div>
          <div class="item-right-bottom-item">
            <p>设备序列号</p>
            <p :title="itemData.serial_no">{{ itemData.serial_no }}</p>
          </div>
        </div>
      </div>
    </div>
    <!-- 单屏监控 -->
    <SingleScreen
      v-if="screenVisible"
      :screenVisible="screenVisible"
      :screenDetail="screenDetail"
      @closeScreen="closeScreen"
    ></SingleScreen>
  </div>
</template>
<script lang="ts" setup>
import {onMounted, ref} from 'vue';
import censusApi from '@/api/census.ts';
import MapRoute from '@/components/comMapRoute/index.vue';
import SingleScreen from '@/views/home/components/SingleScreen.vue';
import store from '@/store';

const itemData = ref({});
const flightData = ref<Object>();
const droneInfo = ref<Object>();
const flightMission = ref<Object>();
const screenVisible = ref(false);
const screenDetail = ref({});
const missionId = ref('');

const props = defineProps({
  itemData: Object,
});

// 获取飞行数据
const getFlightData = (item: object) => {
  item.fmMonitor.onFlightPanelDatasUpdated = () => {
    flightData.value = item.fmMonitor.flightPanelDatas;
  };
  droneInfo.value = item.fmMonitor.droneInfo;
  flightMission.value = item.fmMonitor.flightMission;
};

// 单屏监控
const openSingleScreen = async () => {
  await getMonitorDetail(itemData.value.mission_id);
  screenVisible.value = true;
  store.commit('setFlightState', true);
};

const closeScreen = () => {
  screenVisible.value = false;
};

// 获取监控详情数据
const getMonitorDetail = async (id: string) => {
  await censusApi
    .flightDetail({mission_id: id})
    .then((res) => {
      screenDetail.value = res.data;
    })
    .catch((err) => {
      throw err;
    });
};

onMounted(() => {
  itemData.value = props.itemData;
  missionId.value = props.itemData.mission_id;
});
</script>
<style lang="scss" scoped>
.screen-con-item {
  p,
  ul,
  li {
    margin: 0;
  }
  display: flex;
  font-size: 12px;
  height: auto;
  .item-left {
    width: 292px;
    height: 225px;
    background: #fff;
  }
  .item-right {
    width: 230px;
    height: 225px;
    padding: 22px 16px;
    box-sizing: border-box;
    background: #25346d;
    margin-left: 11px;
    &-top {
      display: flex;
      .top-img {
        width: 34px;
        height: 35px;
        > img {
          width: 100%;
          height: 100%;
        }
      }
      .top-info {
        margin-left: 10px;
        :nth-child(1) {
          margin-bottom: 2px;
        }
      }
    }
    &-con {
      display: flex;
      margin-top: 10px;
      font-size: 16px;
      &-left {
        margin-right: 30px;
        :nth-child(1) {
          color: #19eaff;
          font-weight: bold;
        }
        :nth-child(2) {
          color: #fff;
          opacity: 0.7;
        }
      }
      &-right {
        :nth-child(1) {
          color: #1eff7e;
          font-weight: bold;
        }
        :nth-child(2) {
          color: #fff;
          opacity: 0.7;
        }
      }
    }
    &-line {
      height: 1px;
      background: #3c4d91;
      margin: 10px 0;
    }
    &-bottom {
      > p {
        font-size: 10px;
        margin-bottom: 5px;
        color: #ffc100;
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
      }
      &-item {
        display: flex;
        :nth-child(1) {
          width: 80px;
          margin-right: 10px;
          margin-bottom: 5px;
          opacity: 0.7;
        }
        :nth-child(2) {
          width: 110px;
          overflow: hidden;
          text-overflow: ellipsis;
          white-space: nowrap;
        }
      }
    }
  }
}
</style>
